version 17
set more off
quietly log
local logon = r(status)
	if "`logon'" == "on"  {
	log close	
	}
log using mkdata_unwelcome_immigrants_knocking_on_the_door, text replace

/*******************************************************************************
	Project   : Unwelcome Immigrants Knocking on the Door
	File Name : mkdata_unwelcome_immigrants_knocking_on_the_door.do
	Date	  : Feb 22nd, 2023 (Latest update)
	Purpose	  : Conducting the analysis that is included in the paper.
	Input	  : 1) Latinobarometro (2000 ~ 2018)
	
	Output	  : 1) analysis_unwelcome_immigrants_knocking_on_the_door.log       - Log File
					
******************************************************************************  */
**# 1. Latinobarometro

* Importing Latinobarometro
cd "C:\Users\helxi\Desktop\data\Latinobarometro"
use ".\Latinobarometro_2000_datos_eng_v2014_06_27.dta", clear

keep idenpa numinves S1 S2 reeduc1 S8A S9 P52ST P14CG_A P4ST P30ST P76ST P77ST P17ST P43NST P29ST wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab S1,m
tab S1,m nolab
recode S1 (1=1)(2=0), gen(male)

tab male,m

*age
tab S2,m
rename S2 age

tab age,m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1,m
tab reeduc1,m nolab

rename reeduc1 educ 

tab educ,m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab S8A,m 
tab S8A,m nolab

recode S8A (1/3=1)(4/7=0), gen(employed)

tab employed, m

*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/

tab S9,m
tab S9,m nolab

recode S9 (1=1)(2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation, m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab P52ST, m
tab P52ST, m nolab

recode P52ST (-6/-1=5), gen(ideology_right)
recode P52ST (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

*10 level of economic level
tab P14CG_A,m
tab P14CG_A,m nolab

sum P14CG_A // Mean is 4.29

recode P14CG_A (-6/-1=.), gen(income)
recode P14CG_A (-6/-1=4), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab P4ST,m
tab P4ST,m nolab

recode P4ST (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode P4ST (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4)
tab P30ST,m
tab P30ST,m nolab

recode P30ST (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion 
tab P76ST, m
tab P76ST, m nolab

recode P76ST (-2/-1=0)(1=1)(2/16=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab P77ST,m
tab P77ST,m nolab

recode P77ST (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab P17ST,m
tab P17ST,nolab

recode P17ST (1=1)(2=0)(-2=0),gen(social_trust)

tab social_trust, m

*Confidence in Neighboring countries
tab P43NST,m
tab P43NST,m nolab

rename P43NST confi_neicon_2000

recode confi_neicon_2000 (-2/0=.)(97=.)

*DV - populist attitude (3 level)
tab P29ST,m
tab P29ST,m nolab

recode P29ST (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

save 2000_latino.dta, replace

**# 2001 Latino barometer
use ".\Latinobarometro_2001_datos_english_v2014_06_27.dta", clear

drop if idenpa==724

keep idenpa numinves s1 s2 reeduc1 s8a s9 p54st p8ncg p4st p45st p86st p87st p42st p66sta p46st wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s1,m
tab s1,m nolab
recode s1 (1=1)(2=0), gen(male)

tab male,m

*age
tab s2,m
tab s2,m nolab

rename s2 age

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1, m
tab reeduc1, m nolab

rename reeduc1 educ 
recode educ (-2=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s8a,m 
tab s8a,m nolab

recode s8a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s9,m
tab s9,m nolab
recode s9 (1=1)(2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p54st, m
tab p54st, m nolab

recode p54st (-6/-1=5), gen(ideology_right)
recode p54st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

*income (1~10)
tab p8ncg,m
tab p8ncg,m nolab

sum p8ncg // mean is 5.04

recode p8ncg (-2=.), gen(income)
recode p8ncg (-2=5), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab p4st,m
tab p4st,m nolab

recode p4st (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode p4st (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4)
tab p45st,m
tab p45st,m nolab

recode p45st (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab p86st, m
tab p86st, m nolab

recode p86st (-2/-1=0)(1=1)(2/18=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab p87st,m
tab p87st,m nolab
recode p87st (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p42st,m
tab p42st,nolab

recode p42st (1=1)(2=0)(-2=0),gen(social_trust)

tab social_trust,m

*Confidence in Neighboring countries
tab p66sta, m
tab p66sta, m nolab

rename p66sta confi_neicon_2001

recode confi_neicon_2001 (-2/0=.)(96/97=.)

*DV - populist attitude (3 Level)
tab p46st,m
tab p46st,m nolab

recode p46st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Save and Append
save 2001_latino.dta, replace

**# 2002 Latino barometer
use ".\Latinobarometro_2002_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724

keep idenpa numinves s1 s2 reeduc1 s8a s9 p64st p2std p33st p65st p66st p29st p59st p32st p62no2a wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s1,m
tab s1,m nolab
recode s1 (1=1)(2=0), gen(male)

tab male,m

*age
tab s2,m
tab s2,m nolab

rename s2 age
recode age (-2=.)

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1, m
tab reeduc1, m nolab

rename reeduc1 educ 
recode educ (-2=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s8a,m 
tab s8a,m nolab

recode s8a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s9,m
tab s9,m nolab
recode s9 (1=1)(2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p64st, m
tab p64st, m nolab

recode p64st (-6/-1=5), gen(ideology_right)
recode p64st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* 5 level of economic level (higher is better)
tab p2std,m
tab p2std,m nolab

recode p2std (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode p2std (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4)
tab p33st,m
tab p33st,m nolab

recode p33st (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab p65st, m
tab p65st, m nolab

recode p65st (-2/-1=0)(1=1)(2/18=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab p66st,m
tab p66st,m nolab

recode p66st (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p29st,m
tab p29st,nolab

recode p29st (1=1)(2=0)(-2=0),gen(social_trust)

tab social_trust,m

*Confidence in Neighboring countries
tab p59st, m
tab p59st, m nolab

rename p59st confi_neicon_2002

recode confi_neicon_2002 (-2/0=.)(96/97=.)

*DV - populist attitude (3 Level)
tab p32st,m
tab p32st,m nolab

recode p32st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Immigration attitude - Immigrants take away our jobs
tab p62no2a,m nolab
recode p62no2a (1=5)(2=4)(3=3)(4=2)(5=1)(-2=.), gen(anti_immi_job)

*Save and Append
save 2002_latino.dta, replace

**# 2003 Latino barometer
use ".\Latinobarometro_2003_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724
keep idenpa numinves s1 s2 s18 s8a s9 p60st p4st p15st p91st p92st p20st p14st wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s1,m
tab s1,m nolab
recode s1 (1=1)(2=0), gen(male)

tab male,m

*age
tab s2,m
tab s2,m nolab

rename s2 age
recode age (-2=.)

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab s18, m
tab s18, m nolab

rename s18 educ 
recode educ (-2=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s8a,m 
tab s8a,m nolab

recode s8a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s9,m
tab s9,m nolab
recode s9 (1=1)(2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p60st, m
tab p60st, m nolab

recode p60st (-6/-1=5), gen(ideology_right)
recode p60st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* 5 level of economic level (higher is better)
tab p4st,m
tab p4st,m nolab

recode p4st (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode p4st (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4)
tab p15st,m
tab p15st,m nolab

recode p15st (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab p91st, m
tab p91st, m nolab

recode p91st (-2/-1=0)(1=1)(2/18=0)(96/97=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab p92st,m
tab p92st,m nolab

recode p92st (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p20st,m
tab p20st,nolab

recode p20st (1=1)(2=0)(-2=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level)
tab p14st,m
tab p14st,m nolab

recode p14st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Save and Append
save 2003_latino.dta, replace

**# 2004 Latino barometer
use ".\Latinobarometro_2004_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724
keep idenpa numinves s1 s2 reeduc1 s8a s9 p87st p9sta p5st p14st p90st p91st p43st p47st p13st p10st wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s1,m
tab s1,m nolab
recode s1 (1=1)(2=0), gen(male)

tab male,m

*age
tab s2,m
tab s2,m nolab

rename s2 age
recode age (-2=.)

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1, m
tab reeduc1, m nolab

rename reeduc1 educ
recode educ (0=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s8a,m 
tab s8a,m nolab

recode s8a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s9,m
tab s9,m nolab
recode s9 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p87st, m
tab p87st, m nolab

recode p87st (-6/-1=5), gen(ideology_right)
recode p87st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

*income (1~10)
tab p9sta,m
tab p9sta,m nolab

sum p9sta // mean is 3.01

recode p9sta (-6/-1=.), gen(income)
recode p9sta (-6=3)(-4=.)(-2/-1=3), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab p5st,m
tab p5st,m nolab

recode p5st (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode p5st (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4)
tab p14st,m
tab p14st,m nolab

recode p14st (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab p90st, m
tab p90st, m nolab

recode p90st (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab p91st,m
tab p91st,m nolab

recode p91st (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p43st,m
tab p43st,nolab

recode p43st (1=1)(2=0)(-2=0),gen(social_trust)

tab social_trust,m

*Confidence in Neighboring countries
tab p47st, m
tab p47st, m nolab

rename p47st confi_neicon_2004

recode confi_neicon_2004 (-2/0=.)(96/97=.)

tab confi_neicon_2004,m

*DV - populist attitude (3 Level)
tab p13st,m
tab p13st,m nolab

recode p13st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*anti-immigration - Most important problem
tab p10st,m nolab
recode p10st (4=1)(-2/3=0)(5/97=0), gen(anti_immi_prob)

*Save and Append
save 2004_latino.dta, replace

**# 2005 Latino barometer
use ".\Latinobarometro_2005_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724
keep idenpa numinves s6 s7 reeduc1 s13a s14 p34st p95st p5st p18st s2 s3 p14st p44st p16st p8st wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s6,m
tab s6,m nolab
recode s6 (1=1)(2=0), gen(male)

tab male,m

*age
tab s7,m
tab s7,m nolab

rename s7 age
recode age (-2=.)

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1, m
tab reeduc1, m nolab

rename reeduc1 educ
recode educ (0=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s13a,m 
tab s13a,m nolab

recode s13a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s14,m
tab s14,m nolab
recode s14 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p34st, m
tab p34st, m nolab

recode p34st (-6/-1=5), gen(ideology_right)
recode p34st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

*income (1~10)
tab p95st,m
tab p95st,m nolab

sum p95st // mean is 3.57

recode p95st (-6/-1=.), gen(income)
recode p95st (-6/-1=4), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab p5st,m
tab p5st,m nolab

recode p5st (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode p5st (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4)
tab p18st,m
tab p18st,m nolab

recode p18st (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab s2, m
tab s2, m nolab

recode s2 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab s3,m
tab s3,m nolab

recode s3 (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p14st,m
tab p14st,nolab

recode p14st (1=1)(2=0)(-2=0),gen(social_trust)

tab social_trust,m

*Confidence in Neighboring countries
tab p44st, m
tab p44st, m nolab

rename p44st confi_neicon_2005

recode confi_neicon_2005 (-2/0=.)(23/97=.)

tab confi_neicon_2005,m

*DV - populist attitude (3 Level)
tab p16st,m
tab p16st,m nolab

recode p16st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*anti-immigration - Most important problem
tab p8st,m
recode p8st (4=1)(-2/3=0)(5/97=0), gen(anti_immi_prob)

*Save and Append
save 2005_latino.dta, replace

**# 2006 Latino barometer
use ".\Latinobarometro_2006_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724
keep idenpa numinves s6 s7 reeduc1 s13a s14 p47st p13st_a p5st p21st s2 s3 p45st p49st_a p17st p10st wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s6,m
tab s6,m nolab
recode s6 (1=1)(2=0), gen(male)

tab male,m

*age
tab s7,m
tab s7,m nolab

rename s7 age
recode age (-2=.)

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1, m
tab reeduc1, m nolab

rename reeduc1 educ
recode educ (0=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s13a,m 
tab s13a,m nolab

recode s13a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s14,m
tab s14,m nolab

recode s14 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p47st, m
tab p47st, m nolab

recode p47st (-6/-1=5), gen(ideology_right)
recode p47st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

*income (1~10)
tab p13st_a,m
tab p13st_a,m nolab

sum p13st_a // mean is 4.12

recode p13st_a (-6/-1=.), gen(income)
recode p13st_a (-6/-1=4), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab p5st,m
tab p5st,m nolab

recode p5st (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode p5st (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4)
tab p21st,m
tab p21st,m nolab

recode p21st (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab s2, m
tab s2, m nolab

recode s2 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab s3,m
tab s3,m nolab

recode s3 (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p45st,m
tab p45st,nolab

recode p45st (1=1)(2=0)(-2=0),gen(social_trust)

tab social_trust,m

*Confidence in Neighboring countries
tab p49st_a, m
tab p49st_a, m nolab

rename p49st_a confi_neicon_2006

recode confi_neicon_2006 (-2/0=.)(23/97=.)

tab confi_neicon_2006,m

*DV - populist attitude (3 Level)
tab p17st,m
tab p17st,m nolab

recode p17st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*anti-immigration - Most important problem
tab p10st,m
recode p10st (4=1)(-2/3=0)(5/97=0), gen(anti_immi_prob)

*Save and Append
save 2006_latino.dta, replace

**# 2007 Latino barometer
use ".\Latinobarometro_2007_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724
keep if s8n==1

keep idenpa numinves s10 s11 reeduc1 s17a s18 p67st p6stma p12st s4 s5 p23st p33n p9st p90nh wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s10,m
tab s10,m nolab
recode s10 (1=1)(2=0), gen(male)

tab male,m

*age
tab s11,m
tab s11,m nolab

rename s11 age
recode age (-2=.)

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1, m
tab reeduc1, m nolab

rename reeduc1 educ
recode educ (0=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s17a,m 
tab s17a,m nolab

recode s17a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s18,m
tab s18,m nolab

recode s18 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p67st, m
tab p67st, m nolab

recode p67st (-6/-1=5), gen(ideology_right)
recode p67st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

*income (1~10)
tab p6stma,m
tab p6stma,m nolab

sum p6stma // mean is 4.46

recode p6stma (-6/-1=.), gen(income)
recode p6stma (-6/-1=5), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
recode p6stma (-6/-1=.)(1/2=1)(3/4=2)(5/6=3)(7/8=4)(9/10=5), gen(income_four)
recode p6stma (-6/-1=3)(1/2=1)(3/4=2)(5/6=3)(7/8=4)(9/10=5), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m


*Satisfaction with democracy (1~4)
tab p12st,m
tab p12st,m nolab

recode p12st (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab s4, m
tab s4, m nolab

recode s4 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab s5,m
tab s5,m nolab

recode s5 (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p23st,m
tab p23st,nolab

recode p23st (1=1)(2=0)(-2=0),gen(social_trust)

tab social_trust,m

*Confidence in Neighboring countries
tab p33n, m
tab p33n, m nolab

rename p33n confi_neicon_2007

recode confi_neicon_2007 (-2/0=.)(23/97=.)

tab confi_neicon_2007,m

*DV - populist attitude (3 Level)
tab p9st,m
tab p9st,m nolab

recode p9st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*anti-immigration - Conflict between nationals and immigrants
tab p90nh,m nolab
recode p90nh (1=4)(2=3)(3=2)(4=1)(-2/-1=.), gen(anti_immi_conflict)

*Save and Append
save 2007_latino.dta, replace

**# 2008 Latino barometer
use ".\Latinobarometro_2008_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724
keep if s10==1

keep idenpa numinves s8 s9 reeduc1 s17a s18 p56st p12st_a p7st p22st_a s5 s6 p21wvsst p13st p69st_h wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s8,m
tab s8,m nolab

recode s8 (1=1)(2=0), gen(male)

tab male,m

*age
tab s9,m
tab s9,m nolab

rename s9 age
recode age (-2=.)

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1, m
tab reeduc1, m nolab

rename reeduc1 educ
recode educ (0=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s17a,m 
tab s17a,m nolab

recode s17a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s18,m
tab s18,m nolab

recode s18 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p56st, m
tab p56st, m nolab

recode p56st (-6/-1=5), gen(ideology_right)
recode p56st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

*income (1~10)
tab p12st_a,m
tab p12st_a,m nolab

sum p12st_a // mean is 4.24

recode p12st_a (-6/-1=.), gen(income)
recode p12st_a (-6/-1=4), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab p7st,m
tab p7st,m nolab

recode p7st (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode p7st (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4)
tab p22st_a,m
tab p22st_a,m nolab

recode p22st_a (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab s5, m
tab s5, m nolab

recode s5 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab s6,m
tab s6,m nolab

recode s6 (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p21wvsst,m
tab p21wvsst,nolab

recode p21wvsst (1=1)(2=0)(-2/-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level)
tab p13st,m
tab p13st,m nolab

recode p13st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*anti-immigration - Conflict between nationals and immigrants
tab p69st_h,m
recode p69st_h (1=4)(2=3)(3=2)(4=1)(-2/-1=.), gen(anti_immi_conflict)

*Save and Append
save 2008_latino.dta, replace

**# 2009 Latino barometer
use ".\Latinobarometro_2009_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724 // drop spain
keep if s16==1 // drop non-citizen

keep idenpa numinves s5 s6 reeduc1 s14a s15 p69st p17st_a p6st p12st_a s7 s8 p58st p10st p85st_a p34stm_g wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*male - 1 - Male/ 0 - Female
tab s5,m
tab s5,m nolab

recode s5 (1=1)(2=0), gen(male)

tab male,m

*age
tab s6,m
tab s6,m nolab

rename s6 age
recode age (-2=.)

tab age, m

*education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab reeduc1, m
tab reeduc1, m nolab

rename reeduc1 educ
recode educ (-2=.)

tab educ, m

*Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab s14a,m 
tab s14a,m nolab

recode s14a (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*Occupation employment
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab s15,m
tab s15,m nolab

recode s15 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab p69st, m
tab p69st, m nolab

recode p69st (-6/-1=5), gen(ideology_right)
recode p69st (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

*income (1~10)
tab p17st_a,m
tab p17st_a,m nolab

sum p17st_a // mean is 4.22

recode p17st_a (-6/-1=.), gen(income)
recode p17st_a (-6/-1=4), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better) personal current economic situation
tab p6st,m
tab p6st,m nolab

recode p6st (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode p6st (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*Satisfaction with democracy (1~4) 
tab p12st_a,m
tab p12st_a,m nolab

recode p12st_a (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab s7, m
tab s7, m nolab

recode s7 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1~4) (higher)
tab s8,m
tab s8,m nolab

recode s8 (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab p58st,m
tab p58st,nolab

recode p58st (1=1)(2=0)(-2/-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level)
tab p10st,m
tab p10st,m nolab

recode p10st (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Immigration attitude - Immigrants take away our jobs
tab p85st_a,m nolab
recode p85st_a (1=5)(2=4)(3=3)(4=2)(5=1)(-2=.), gen(anti_immi_job)

*anti-immigration - Conflict between nationals and immigrants
tab p34stm_g,m
recode p34stm_g (1=4)(2=3)(3=2)(4=1)(-2/-1=.), gen(anti_immi_conflict)

*Save and Append
save 2009_latino.dta, replace

**# 2010 Latino barometer
use ".\Latinobarometro_2010_datos_eng_v2014_06_27.dta", clear
drop if idenpa==724 // drop spain
keep if S18==1 // drop non-citizen

keep idenpa numinves S7 S8 REEDUC1 S16A S17 P60ST P13ST_A P6ST P11ST_A S9 S10 P55ST P10ST P27ST_G P69ST_A wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*S7_SEX: male - 1 - Male/ 0 - Female
tab S7,m
tab S7,m nolab

recode S7 (1=1)(2=0), gen(male)

tab male,m

*S8: age
tab S8,m
tab S8,m nolab

rename S8 age
recode age (-2=.)

tab age, m

*REEDUC1: education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab REEDUC1, m
tab REEDUC1, m nolab

rename REEDUC1 educ
recode educ (0=.)

tab educ, m

*S16A: Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab S16A,m 
tab S16A,m nolab

recode S16A (1/3=1)(4/7=0)(-2=0), gen(employed)

tab employed,m

*Occupation
*S17: Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab S17,m
tab S17,m nolab

recode S17 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*P60ST: ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab P60ST, m
tab P60ST, m nolab

recode P60ST (-6/-1=5), gen(ideology_right)
recode P60ST (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* P13ST_A: income (1~10)
tab P13ST_A,m
tab P13ST_A,m nolab

sum P13ST_A // mean is 4.1

recode P13ST_A (-6/-1=.), gen(income)
recode P13ST_A (-6/-1=4), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab P6ST,m
tab P6ST,m nolab

recode P6ST (-3/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode P6ST (-3/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*P11ST_A: Satisfaction with democracy (1~4)
tab P11ST_A,m
tab P11ST_A,m nolab

recode P11ST_A (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab S9, m
tab S9, m nolab

recode S9 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1~4)
tab S10,m
tab S10,m nolab

recode S10 (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab P55ST,m
tab P55ST,nolab

recode P55ST (1=1)(2=0)(-2/-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level)
tab P10ST,m
tab P10ST,m nolab

recode P10ST (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Immigration attitude - Immigrants take away our jobs
tab P69ST_A,m nolab
recode P69ST_A (1=5)(2=4)(3=3)(4=2)(5=1)(-2=.), gen(anti_immi_job)

*anti-immigration - Conflict between nationals and immigrants
tab P27ST_G,m
recode P27ST_G (1=4)(2=3)(3=2)(4=1)(-2/-1=.), gen(anti_immi_conflict)

*Save and Append
save 2010_latino.dta, replace

**# 2011 Latino barometer
use ".\Latinobarometro_2011_eng.dta", clear
keep if S25==1 // drop non-citizen

keep idenpa numinves S16 S17 REEDUC1 S23A S24 P76ST P11ST_A P6ST P14ST_A S18 S18_A P25ST P13ST wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*S16_SEX: male - 1 - Male/ 0 - Female
tab S16,m
tab S16,m nolab

recode S16 (1=1)(2=0), gen(male)

tab male,m

*S17: age
tab S17,m
tab S17,m nolab

rename S17 age
recode age (-2=.)

tab age, m

*REEDUC1: education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab REEDUC1, m
tab REEDUC1, m nolab

rename REEDUC1 educ
recode educ (0=.)

tab educ, m

*S23A: Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab S23A,m 
tab S23A,m nolab

recode S23A (1/3=1)(4/7=0), gen(employed)

tab employed,m

*P76ST: ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab P76ST, m
tab P76ST, m nolab

recode P76ST (-6/-1=5), gen(ideology_right)
recode P76ST (-6/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* P11ST_A: income (1~10)
tab P11ST_A,m
tab P11ST_A,m nolab

sum P11ST_A // mean is 4.552861 (Round up to 5)

recode P11ST_A (-6/-1=.), gen(income)
recode P11ST_A (-6/-1=5), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab P6ST,m
tab P6ST,m nolab

recode P6ST (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode P6ST (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*P14ST_A: Satisfaction with democracy (1~4)
tab P14ST_A,m
tab P14ST_A,m nolab

recode P14ST_A (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab S18, m
tab S18, m nolab

recode S18 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1 very practicing ~ 4 not practising at all)
tab S18_A,m
tab S18_A,m nolab

recode S18_A (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab P25ST,m
tab P25ST,nolab

recode P25ST (1=1)(2=0)(-2/-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level, 1-democracy preferable)
tab P13ST,m
tab P13ST,m nolab

recode P13ST (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Save and Append
save 2011_latino.dta, replace

**# 2013 Latino barometer
use ".\Latinobarometro2013Eng.dta", clear
drop if idenpa==724 // drop spain
keep if S12==1 // drop non-citizen

keep idenpa numinves S10 S11 REEDUC_1 S19_A S20 P41ST P11ST_A P6STGBS P13TGB_A S14 S14_A P29STGBS P12STGBS wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*S10_SEX: male - 1 - Male/ 0 - Female
tab S10,m
tab S10,m nolab

recode S10 (1=1)(2=0), gen(male)

tab male,m

*S11: age
tab S11,m
tab S11,m nolab

rename S11 age
recode age (-2=.)

tab age, m

*REEDUC_1: education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab REEDUC_1, m
tab REEDUC_1, m nolab

rename REEDUC_1 educ
recode educ (-2=.)

tab educ, m

*S19_A: Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab S19_A,m 
tab S19_A,m nolab

recode S19_A (1/3=1)(4/7=0)(-4=.), gen(employed)

tab employed,m

*P41ST: ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab P41ST, m
tab P41ST, m nolab

recode P41ST (-8/-1=5), gen(ideology_right)
recode P41ST (-8/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* P11ST_A: income (1~10)
tab P11ST_A,m
tab P11ST_A,m nolab

sum P11ST_A // mean is 4.35 (Round down to 4)

recode P11ST_A (-2/-1=.), gen(income)
recode P11ST_A (-2/-1=4), gen(income_mean)

tab income,m
tab income_mean,m

* 5 level of economic level (higher is better)
tab P6STGBS ,m
tab P6STGBS ,m nolab

recode P6STGBS  (-4/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode P6STGBS  (-4/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*P13TGB_A: Satisfaction with democracy (1~4)
tab P13TGB_A,m
tab P13TGB_A,m nolab

recode P13TGB_A (-4/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab S14, m
tab S14, m nolab

recode S14 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1 very practicing ~ 4 not practising at all)
tab S14_A,m
tab S14_A,m nolab

recode S14_A (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab P29STGBS,m
tab P29STGBS,nolab

recode P29STGBS (1=1)(2=0)(-2/-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level, 1-democracy preferable)
tab P12STGBS,m
tab P12STGBS,m nolab

recode P12STGBS (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Save and Append
save 2013_latino.dta, replace

**# 2015 Latino barometer
use ".\Latinobarometro_2015_Eng.dta", clear
keep if S12==1 // drop non-citizen

keep idenpa numinves S12 S13 REEDUC_1 S21_A S22 P27ST P6STGBS P12TG_A S16 S16_A P15STGBS P11STGBS P44ST_A wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*S10_SEX: male - 1 - Male/ 0 - Female
tab S12,m
tab S12,m nolab

recode S12 (1=1)(2=0), gen(male)

tab male,m

*S11: age
tab S13,m
tab S13,m nolab

rename S13 age
recode age (-2=.)

tab age, m

*REEDUC_1: education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab REEDUC_1, m
tab REEDUC_1, m nolab

rename REEDUC_1 educ
recode educ (-2=.)

tab educ, m

*S21_A: Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab S21_A,m 
tab S21_A,m nolab

recode S21_A (1/3=1)(4/7=0), gen(employed)

tab employed,m


*Occupation
*S22: Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab S22,m
tab S22,m nolab

recode S22 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3/-2=.),gen(high_occupation)

tab high_occupation,m

*P41ST: ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab P27ST, m
tab P27ST, m nolab

recode P27ST (-8/-1=5), gen(ideology_right)
recode P27ST (-8/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* 5 level of economic level (higher is better)
tab P6STGBS,m
tab P6STGBS,m nolab

recode P6STGBS (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode P6STGBS (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*P12TG_A: Satisfaction with democracy (1~4)
tab P12TG_A,m
tab P12TG_A,m nolab

recode P12TG_A (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab S16, m
tab S16, m nolab

recode S16 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1 very practicing ~ 4 not practising at all)
tab S16_A,m
tab S16_A,m nolab

recode S16_A (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab P15STGBS,m
tab P15STGBS,nolab

recode P15STGBS (1=1)(2=0)(-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level, 1-democracy preferable)
tab P11STGBS,m
tab P11STGBS,m nolab

recode P11STGBS (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Immigration attitude - Immigrants take away our jobs
tab P44ST_A,m nolab
recode P44ST_A (1=5)(2=4)(3=3)(4=2)(5=1)(-1=.), gen(anti_immi_job)

*Save and Append
save 2015_latino.dta, replace

**# 2016 Latino barometer
use ".\Latinobarometro2016Eng_v20170205.dta", clear
keep if S7==1 // drop non-citizen

keep idenpa numinves sexo edad REEDUC_1 S18A S19 P17ST S22 P9STGBSA S8 S8A P12STGBS P8STGBS wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*sexo_SEX: male - 1 - Male/ 0 - Female
tab sexo,m
tab sexo,m nolab

recode sexo (1=1)(2=0), gen(male)

tab male,m

*edad: age
tab edad,m
tab edad,m nolab

rename edad age
recode age (-2=.)

tab age, m

*REEDUC_1: education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab REEDUC_1, m
tab REEDUC_1, m nolab

rename REEDUC_1 educ
recode educ (-2=.)

tab educ, m

*S18A: Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab S18A,m 
tab S18A,m nolab

recode S18A (1/3=1)(4/7=0), gen(employed)

tab employed,m

*Occupation
*S19: Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab S19,m
tab S19,m nolab

recode S19 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3=.),gen(high_occupation)

tab high_occupation,m

*P17ST: ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab P17ST, m
tab P17ST, m nolab

recode P17ST (-8/-1=5), gen(ideology_right)
recode P17ST (-8/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* 5 level of economic level (higher is better)
tab S22,m
tab S22,m nolab

recode S22 (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode S22 (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m


*P12TG_A: Satisfaction with democracy (1~4)
tab P9STGBSA,m
tab P9STGBSA,m nolab

recode P9STGBSA (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab S8, m
tab S8, m nolab

recode S8 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1 very practicing ~ 4 not practising at all)
tab S8A,m
tab S8A,m nolab

recode S8A (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab P12STGBS,m
tab P12STGBS,nolab

recode P12STGBS (1=1)(2=0)(-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level, 1-democracy preferable)
tab P8STGBS,m
tab P8STGBS,m nolab

recode P8STGBS (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*Save and Append
save 2016_latino.dta, replace

**# 2017 Latino barometer
use ".\Latinobarometro2017Eng_v20180117.dta", clear
keep if S8==1 // drop non-citizen

keep idenpa numinves sexo edad REEDUC_1 S18_A S19 P19STC S22 P9STGBSC_A S9 S9_A P13STGBS P8STGBS P21ST_H wt

*Renaming & Recoding
rename idenpa country
rename numinves year

*sexo_SEX: male - 1 - Male/ 0 - Female
tab sexo,m
tab sexo,m nolab

recode sexo (1=1)(2=0), gen(male)

tab male,m

*edad: age
tab edad,m
tab edad,m nolab

rename edad age
recode age (-2=.)

tab age, m

*REEDUC_1: education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/
tab REEDUC_1, m
tab REEDUC_1, m nolab

rename REEDUC_1 educ
recode educ (-2=.)

tab educ, m

*S18_A: Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab S18_A,m 
tab S18_A,m nolab

recode S18_A (1/3=1)(4/7=0), gen(employed)

tab employed,m


*Occupation
*S19: Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab S19,m
tab S19,m nolab

recode S19 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3=.),gen(high_occupation)

tab high_occupation,m

*P19STC: ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab P19STC, m
tab P19STC, m nolab

recode P19STC (-8/-1=5), gen(ideology_right)
recode P19STC (-8/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* 5 level of economic level (higher is better)
tab S22,m
tab S22,m nolab

recode S22 (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode S22 (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*P9STGBSC_A: Satisfaction with democracy (1~4)
tab P9STGBSC_A,m
tab P9STGBSC_A,m nolab

recode P9STGBSC_A (-2/-1=.)(1=4)(2=3)(3=2)(4=1), gen(satis_dem)

tab satis_dem,m

*religion - Catholic is 1
tab S9, m
tab S9, m nolab

recode S9 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1 very practicing ~ 4 not practising at all)
tab S9_A,m
tab S9_A,m nolab

recode S9_A (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab P13STGBS,m
tab P13STGBS,nolab

recode P13STGBS (1=1)(2=0)(-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level, 1-democracy preferable)
tab P8STGBS,m
tab P8STGBS,m nolab

recode P8STGBS (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

*anti-immigration - Conflict between nationals and immigrants
tab P21ST_H,m
recode P21ST_H (1=4)(2=3)(3=2)(4=1)(-2/-1=.), gen(anti_immi_conflict)

*Save and Append
save 2017_latino.dta, replace

**# 2018 Latino barometer
use ".\Latinobarometro_2018_Esp_Stata_v20190303.dta", clear
keep if S16==1 // drop non-citizen

*Renaming & Recoding
rename IDENPA country
rename NUMINVES year

*sexo_SEX: male - 1 - Male/ 0 - Female
tab SEXO,m
tab SEXO,m nolab

recode SEXO (1=1)(2=0), gen(male)

tab male,m

*edad: age
tab EDAD,m
tab EDAD,m nolab

rename EDAD age
recode age (-2=.)

tab age, m

*reeduc_1: education
/* illiterate / 
Incomplete primary/ complete primary/ 
incomplete secondary/ complete secondary/ 
incomplete high/ complete high
*/

tab REEDUC_1, m
tab REEDUC_1, m nolab

rename REEDUC_1 educ_2018

*S14A: Employment
/*
Self employed/ salaried employee in a public or private - 1
Tempraliy out of work/ retired/ don't work/ student - 0
missing - 0
*/
tab S14A,m 
tab S14A,m nolab

recode S14A (1/3=1)(4/7=0), gen(employed)

tab employed,m


*Occupation
*S15: Occupation
/*
Professional, business owner, senior or middle management - 1
others - 0
missing is missing
*/
tab S15,m
tab S15,m nolab

recode S15 (1/2=1)(3/4=0)(5/7=1)(8=0)(-3=.),gen(high_occupation)

tab high_occupation,m



*P22ST: ideology (0~10)
*None/ no answer/ don't know goes to middle (5)
tab P22ST, m
tab P22ST, m nolab

recode P22ST (-8/-1=5), gen(ideology_right)
recode P22ST (-8/-1=.), gen(ideology_right_missing)

tab ideology_right,m
tab ideology_right_missing,m

* 5 level of economic level (higher is better)
tab S26,m
tab S26,m nolab

recode S26 (-2/-1=.)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four)
recode S26 (-2/-1=3)(1=5)(2=4)(3=3)(4=2)(5=1), gen(income_four_mean)

tab income_four,m
tab income_four_mean,m

*religion - Catholic is 1
tab S5, m
tab S5, m nolab

recode S5 (-2/-1=0)(1=1)(2/97=0), gen(catholic)

tab catholic,m

*Religiosity (1 very practicing ~ 4 not practising at all)
tab S5A,m
tab S5A,m nolab

recode S5A (-3/-1=.)(1=4)(2=3)(3=2)(4=1), gen(religiosity)

tab religiosity,m

*social trust (1 - trust people)
tab P11STGBS
tab P11STGBS,nolab

recode P11STGBS (1=1)(2=0)(-1=0),gen(social_trust)

tab social_trust,m

*DV - populist attitude (3 Level, 1-democracy preferable)
tab P12STGBS,m
tab P12STGBS,m nolab

recode P12STGBS (1=1)(2=2)(3=3)(-2/-1=.), gen(open_auto)

tab open_auto,m

rename WT wt

save 2018_latino.dta, replace

**# Merge Micro data and Macro data
use 2000_latino.dta, clear

append using 2001_latino.dta
append using 2002_latino.dta
append using 2003_latino.dta
append using 2004_latino.dta
append using 2005_latino.dta
append using 2006_latino.dta
append using 2007_latino.dta

append using 2008_latino.dta
append using 2009_latino.dta
append using 2010_latino.dta
append using 2011_latino.dta
append using 2013_latino.dta

append using 2015_latino.dta
append using 2016_latino.dta
append using 2017_latino.dta

append using 2018_latino.dta

recode year (16=2011)(17=2013)(18=2015)

gen educ_three =.

replace educ_three=1 if educ==1
replace educ_three=1 if educ==2
replace educ_three=1 if educ==3
replace educ_three=2 if educ==4
replace educ_three=2 if educ==5
replace educ_three=3 if educ==6
replace educ_three=3 if educ==7

replace educ_three=1 if educ_2018==1
replace educ_three=2 if educ_2018==2
replace educ_three=3 if educ_2018==3

tab educ_three, m

drop  if country== 184 | country== 214 |country== 222|country== 320|country== 340|country== 484|country== 558 |country== 591|country== 188
tab country,m

tab country, nolab m
gen cow = .

replace cow = 160 if country==32
replace cow = 145 if country==68
replace cow = 140 if country==76
replace cow = 155 if country==152
replace cow = 100 if country==170
replace cow = 130 if country==218
replace cow = 150 if country==600
replace cow = 135 if country==604
replace cow = 165 if country==858
replace cow = 101 if country==862

tab cow, m
tab year, nolab

recode religiosity (.=1)

keep country cow year open_auto age male educ_three employed income_four_mean ideology_right catholic religiosity ///
	 anti_immi_job anti_immi_prob anti_immi_conflict wt

kountry cow, from(cown) marker
tab MARKER
rename NAMES_STD country_name_kountry
drop MARKER country

save "master_022523.dta", replace

cd "C:\Users\helxi\Desktop\Study\Research\Research Project\Submission & R and R\Unwelcome Immigrants Knocking on the Door (With Jeongnam)\DATA"
use "master_022523.dta", clear
merge m:1 country_name_kountry year using "macro_level.dta"

tab open_auto, nolab m
recode open_auto (1=0)(2=1)(3=.), gen(open_auto_binary)
tab open_auto_binary,m

order country country_name_kountry country_name_n cow year source ///
      total_immi total_immi_ipo total_male_immi total_male_immi_ipo total_female_immi total_female_immi_ipo ///
	  male_per male_per_ipo total_immi_per_pop total_immi_per_pop_ipo male_immi_per_pop male_immi_per_pop_ipo ///
	  female_immi_per_pop female_immi_per_pop_ipo working1564_num working1564_num_ipo working2455_num working2455_num_ipo ///
	  working1564_per working1564_per_ipo working2455_per working2455_per_ipo male_working1564_per male_working1564_per_ipo ///
	  male_working2455_per male_working2455_per_ipo working1564_per_pop working1564_per_pop_ipo working2455_per_pop ///
	  working2455_per_pop_ipo male_working1564_per_pop male_working1564_per_pop_ipo male_working2455_per_pop ///
	  male_working2455_per_pop_ipo econ_index econ_index_ipo econ_index_nomiss econ_index_nomiss_ipo rich_immi_prop ///
	  rich_immi_prop_ipo gdppc_wb gdppc_wb_ipo cnt_unemployment_ilo_wb cnt_unemployment_ne_wb cnt_libdem_vdem cnt_regime_vdem ///
	  open_auto_binary age male educ_three employed income_four_mean ideology_right catholic religiosity ///
	  anti_immi_job anti_immi_prob anti_immi_conflict wt
	  
mdesc country country_name_kountry country_name_n cow year source ///
      total_immi total_immi_ipo total_male_immi total_male_immi_ipo total_female_immi total_female_immi_ipo ///
	  male_per male_per_ipo total_immi_per_pop total_immi_per_pop_ipo male_immi_per_pop male_immi_per_pop_ipo ///
	  female_immi_per_pop female_immi_per_pop_ipo working1564_num working1564_num_ipo working2455_num working2455_num_ipo ///
	  working1564_per working1564_per_ipo working2455_per working2455_per_ipo male_working1564_per male_working1564_per_ipo ///
	  male_working2455_per male_working2455_per_ipo working1564_per_pop working1564_per_pop_ipo working2455_per_pop ///
	  working2455_per_pop_ipo male_working1564_per_pop male_working1564_per_pop_ipo male_working2455_per_pop ///
	  male_working2455_per_pop_ipo econ_index econ_index_ipo econ_index_nomiss econ_index_nomiss_ipo rich_immi_prop ///
	  rich_immi_prop_ipo gdppc_wb gdppc_wb_ipo cnt_unemployment_ilo_wb cnt_unemployment_ne_wb cnt_libdem_vdem cnt_regime_vdem ///
	  open_auto_binary age male educ_three employed income_four_mean ideology_right catholic religiosity ///
	  anti_immi_job anti_immi_prob anti_immi_conflict wt
	  
keep country country_name_kountry country_name_n cow year source ///
      total_immi total_immi_ipo total_male_immi total_male_immi_ipo total_female_immi total_female_immi_ipo ///
	  male_per male_per_ipo total_immi_per_pop total_immi_per_pop_ipo male_immi_per_pop male_immi_per_pop_ipo ///
	  female_immi_per_pop female_immi_per_pop_ipo working1564_num working1564_num_ipo working2455_num working2455_num_ipo ///
	  working1564_per working1564_per_ipo working2455_per working2455_per_ipo male_working1564_per male_working1564_per_ipo ///
	  male_working2455_per male_working2455_per_ipo working1564_per_pop working1564_per_pop_ipo working2455_per_pop ///
	  working2455_per_pop_ipo male_working1564_per_pop male_working1564_per_pop_ipo male_working2455_per_pop ///
	  male_working2455_per_pop_ipo econ_index econ_index_ipo econ_index_nomiss econ_index_nomiss_ipo rich_immi_prop ///
	  rich_immi_prop_ipo gdppc_wb gdppc_wb_ipo cnt_unemployment_ilo_wb cnt_unemployment_ne_wb cnt_libdem_vdem cnt_regime_vdem ///
	  open_auto_binary age male educ_three employed income_four_mean ideology_right catholic religiosity ///
	  anti_immi_job anti_immi_prob anti_immi_conflict wt

sort country year
by country: gen total_immigration_ipo_lag = total_immi_ipo[_n-1]
by country: gen total_immi_per_pop_ipo_lag = total_immi_per_pop_ipo[_n-1]
by country: gen male_per_ipo_lag = male_per_ipo[_n-1]

by country: gen working1564_num_ipo_lag = working1564_num_ipo[_n-1]
by country: gen working2455_num_ipo_lag = working2455_num_ipo[_n-1]

by country: gen working1564_per_ipo_lag = working1564_per_ipo[_n-1]
by country: gen working2455_per_ipo_lag = working2455_per_ipo[_n-1]

by country: gen male_working1564_per_ipo_lag = male_working1564_per_ipo[_n-1]
by country: gen male_working2455_per_ipo_lag = male_working2455_per_ipo[_n-1]

by country: gen working1564_per_pop_ipo_lag = working1564_per_pop_ipo[_n-1]
by country: gen working2455_per_pop_ipo_lag = working2455_per_pop_ipo[_n-1]

by country: gen econ_index_ipo_lag        = econ_index_ipo[_n-1]
by country: gen econ_index_nomiss_ipo_lag = econ_index_nomiss_ipo[_n-1]

by country: gen rich_immi_prop_ipo_lag = rich_immi_prop_ipo[_n-1]
by country: gen gdppc_wb_ipo_lag = gdppc_wb_ipo[_n-1]

by country: gen cnt_unemployment_ilo_wb_lag = cnt_unemployment_ilo_wb[_n-1]
by country: gen cnt_libdem_vdem_lag = cnt_libdem_vdem[_n-1]
by country: gen cnt_regime_vdem_lag = cnt_regime_vdem[_n-1]
              
drop if year<2000
save "data_unwelcome_immigrants_knocking_on_the_door.dta", replace

log close
clear